/***************************************************************************
 *   Copyright (C) 2008 by Thomas Fannes                                   *
 *   thomasfannes@gmail.com                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef STRUCTUREHGVECTOR_H
#define STRUCTUREHGVECTOR_H

#include <QDataStream>

namespace structure
{
	class HexVector
	{
		public:
			// constructors and destructor
			HexVector();
			HexVector(int x, int y, int z);
			HexVector(const HexVector & other);
			~HexVector();

			// operator overloading
			bool operator<(const HexVector & rhs) const;
			bool operator>(const HexVector & rhs) const;
			HexVector & operator=(const HexVector & rhs);
			HexVector operator+(const HexVector & rhs) const;
			HexVector operator-(const HexVector & rhs) const;
			HexVector operator-() const;
			HexVector & operator+= ( const HexVector & rhs );
			HexVector & operator-= ( const HexVector & rhs );
			bool operator==(const HexVector & rhs) const;
			bool operator!=(const HexVector & rhs) const;

			// getters and setters
			int getX() const { return x;};
			int getY() const { return y;};
			int getZ() const { return z;};
			void setX(int iX);
			void setY(int iY);
			void setZ(int iZ);
			void setCoordinates(int iX, int iY, int iZ);
			int getSum() const;
			int & rX() { return x; };
			int & rY() { return y; };
			int & rZ() { return z; };

			// helpfull functions
			float getDistance(const HexVector & other) const;
			float getCenterDistance() const;
			static float getDistance(const HexVector & vct1, const HexVector & vct2);
			static float getCenterDistance(const HexVector & vct1);

		private:
			void toCanonical();

		public:
			friend QDataStream & operator<<(QDataStream & stream, const HexVector & vector)
			{
				return stream << vector.x << vector.y << vector.z;
			};
			friend QDataStream & operator>>(QDataStream & stream, HexVector & vector)
			{
				return stream >> vector.x >> vector.y >> vector.z;
			};

		private:
			int x;
			int y;
			int z;
	};
}

#endif
